package com.ksd.common.ex;

import com.ksd.common.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class BussinessException extends RuntimeException {
    private Integer code;

    /**
     * 接受状态码和消息
     * @param code
     * @param message
     */
    public BussinessException(Integer code, String message) {
        super(message);
        this.code=code;
    }

    /**
     * 接收枚举类型
     * @param resultCodeEnum
     */
    public BussinessException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    /**
     * 如果满足条件，抛出异常
     * @param condition 条件
     * @param resultCodeEnum 类型
     */
    public static void throwMatch(boolean condition, ResultCodeEnum resultCodeEnum) {
        if (condition){
            throw new BussinessException(resultCodeEnum);
        }
    }
}